import { Raycaster, Vector3 } from "three";
import { useAddTools } from "@/utils/useAddTools";
import { storeToRefs } from "pinia";
import { useViewportStore } from "@/store/viewport";

const raycaster = new Raycaster();
const viewportStore = useViewportStore();
const { baseVec } = storeToRefs(viewportStore);
export function getPath (vec: Vector3) {
  const { hasGroup } = useAddTools();
  const group = hasGroup('巷道');
  if (group === null) return;
  const vec1 = vec.clone().sub(baseVec.value)
  raycaster.set(vec1, new Vector3(0, 1, 0));
  raycaster.far = 8;
  const intersects = raycaster.intersectObjects(group.children, true);
  if (intersects.length > 0) {
    return intersects[0].object;
  }
}